import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import autoImport from 'unplugin-auto-import/vite'
import compression from 'vite-plugin-compression'
import vueDevTools from 'vite-plugin-vue-devtools'
import Unocss from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue({
      template: {
        //这些是自定义元素，应该被排除在组件解析之外。
        compilerOptions: {
          isCustomElement: (tag) => tag.startsWith('swiper-'),
        },
      },
    }),
    // autoImport({
    //   imports: ['vue', 'vue-router'],
    //   dts: false,
    // }) as any,
    compression({
      ext: '.br',
      algorithm: 'brotliCompress',
      deleteOriginFile: true,
    }),
    AutoImport({
      imports: ['vue', 'vue-router'],
      include: [/\.vue$/],
      resolvers: [ElementPlusResolver()],
      dts: true, // 确保生成类型定义文件
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    vueDevTools(),
    Unocss(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '#': fileURLToPath(new URL('./types', import.meta.url)),
    },
  },
})
